-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPIKE] "Alert" component - actions implementation #104
Conversation
Made tweaks along the way: -Change title to required, body optional - Clarify icon is set at 24
Was debugging the failed test
From looking at the other components, we don't want to include <p> (and makes sense with all the globals on <p> e.g. in cloud-ui)
CR - Alert base tweaks
|
This pull request is being automatically deployed with Vercel (learn more). hds-flight-website – ./🔍 Inspect: https://vercel.com/hashicorp/hds-flight-website/4QKC51dPu9jDgTvMhmPwMCk4YLwZ hds-components – ./🔍 Inspect: https://vercel.com/hashicorp/hds-components/8CTDH9SQQkvKPZCSYvW4xV2rp1Qt |
@amyrlam have a look at the code above. tomorrow we can discuss it together (I'll set up a meeting) |
ef048af
to
7ed9b00
Compare
|
||
{{#if @description}} | ||
<div class="hds-alert__description">{{@description}}</div> | ||
{{#if @actions}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at any use cases in the "real world" of consumers yet, but I think that this is a really interesting approach! I can't recall seeing an Ember component that strongly recommends a default, but allows an escape hatch, in this manner
…ts in named block
Some thoughts about the proposed patternsThe problem we're trying to solveAccording to the design specifications for the Also, there is no pre-defined list of actions: in some case we have none, in some cases only a So the question (problem) is: how do we allow the consumers to specify which buttons/links to use as actions in the Below I try to explain what are the possible options, what are the pros/cons and my thoughts on them. Option 1 - Just yield in a
|
✅ I'd like to cast a vote in preference of "Option 1 - Just yield in a named block called actions" from the perspective of an HDS consumer. 👍 Let's keep it simple, composable, and stay flexible. In terms of the cited CONS: listed for your "Option 1":
Looking at this holistically, my inference is that these seem motivated by a desire to try to govern designs. Is that correct? I think that's absolutely an important consideration for consistency, and encouraging best practices. However, I'd argue that it'd be much more effective to catch heuristic design misses during design review, rather than through a restrictive Ember component API in code during implementation. I've observed UI engineers generally implement whatever's in Figma mocks, very faithfully (often to the pixel) IRL. Given that the Figma mock is being faithfully implemented: IMO setting up UI engineers to "police" design inconsistencies after a design has been approved and handed off sounds like it could cause friction, and be potentially wasteful. (🧂 Grain of salt ... these are my own opinions / observations.) |
I vote for Option 1 Also, I am curious about Option 3. It looks like Option 3 limits the order that the actions render. Is this intentional? |
I'm in favour of option 1 or option 2, which use yielded blocks. Either of these are idiomatic of Ember, whereas option 3 relies on an invented schema (therefor greater cognitive overhead) for passing in "actions", a term that is already used by Ember components. I would caution against exerting compositional control as noted in option 3. Over time, designs can and will specify new and novel compositions that design systems didn't anticipate. It seems unnecessarily fraught to attempt to enumerate all possible use cases up front. Such novel compositions could be both intentional and useful. Thus, we should leave ourselves as much flexibility as possible to achieve novel designs. I see the argument for consistency. However, design is rarely 100% consistent in the real world. Let's plan for that. |
Just gonna chime in here and repeat what others said: FE more often than not builds what design specs out, so if things are consistent across designs, there shouldn't be a worry about what gets built. That mixed with the likelihood of users copy and pasting from docs (which I think is very likely) I think the instances of "mis-use" are likely to be small. I'd think that option 1 is still possible if option 2 is implemented (there's nothing forcing consumers to use the yielded components). So either of these is fine for me. @didoo your question about passing default args when using the |
💡 Ah, that's a great observation @meirish ... the lowest-common-denominator of "Option 2" is really "Option 1" in practice anyway. |
Thank you @jesdavpet @venusang @randallmorey @meirish for the precious feedback. I am closing this PR for now, and I'll implement option 2 in a separate PR so the history is clean (and we avoid the conflicts). /cc @amyrlam |
Update after #245While finalizing #245 we came around an issue related to whitespace, in particular on how Ember treats whitespace and named blocks and yielded/contextual components. I'll try to explain the issue here, what we learned trying to solve it, and how this affected the API implementation of The problemThe initial implementation of the When tested locally, in the showcase page, everything worked perfectly. But when trying to adopt the component in Cloud UI (see https://github.com/hashicorp/cloud-ui/pull/2429) we came across a problem with the whitespace. Essentially the invocation in Cloud UI looked like this: When this alert was rendered, it had an extra visible space below the text because the The reason for this is in the
At first sight this code makes totally sense, and one would not expect to see the block generated in the component (remember the condition The first thought was to just invert the code in the invocation:
and move the The reason for this, even though counter-intuitive, is that the After spending almost one day trying to figure out this, I asked help in the #tech-frontend Slack channel and I found out that there was a way in Ember to remove the extra whitespace using a specific syntax in Handlebars ( So I added these squishies in the component code, and this fixed the issue. Yay!! But... The "Toast" componentIn the continuation of the work around #245 we have decided to split the After a few back and forth and tests and request for help (again) in the Slack channel we came up with this nice API for the But again the whitespace problem hit us! The space before/after the yield, inside the The reason for that (that's my understanding) is that what we're doing somehow is passing a "function" not just a block, or content, so the block is not undefined anyway. We tested also an approach following what is done in this UI library code (https://github.com/prysmex/ember-eui) essentially defining a specific prop The only way, again, to solve the problem was not only to remove the whitespace from the In the thread on Slack it was pointed out that this is a known issue, and no one has a real solution to the problem: The "solution"At the end the decision I took was this:
The final API for the component looked like this at the end (we also added a
Update: Even more on the whitespace problem:
|
📌 Summary
This is an initial attempt to add support for the
actions
feature in theAlert
component.I have implemented two ways to add actions to an alert:
@actions
argument (an array of objects) over which to loop and insert the corresponding HDS component<:actions>
named block that can be used to add any content into the "action" areaThe reasons for having both is because we want to provide two ways for the users to declare the actions, a "controlled" one (that automatically sets the layout and possibly the
size
of the actions and maybe other properties by default) and an "escape hatch" in case they need to do something different/custom.👉 Notice: at the moment I am not sure the
@actions
prop can do exactly what I have in mind (eg. does thehash
work also for functions/callbacks? how do we pass extra attributes that then can be splashed on the element? etc). Also, I am not sure the consumers will like this approach (it's a pattern more common/standard in React, where you can pass and spread props more easily than in Ember), they may prefer to just yield the action elements via the named block (but this in this case doesn't allow us to control spacing, layout, etc). See thread below for further discussion.👀 How to review
👉 Review by files changed
Reviewer's checklist:
💬 Please consider using conventional comments when reviewing this PR.